﻿#include <libcomm.h>

class A
{
public:
	A() :i(100) { printf("A(%d);\n",i);  }
	~A() { printf("~A(%d);\n",i); }
	void set(int a) { i = a; }
	int get() { return i; }
private:
	int i;
};


static LocalVar<A> s_var;

int ThreadProcTest(CommType& arg)
{
	int i = arg;
	//Thread::Sleep(2000);
	A* a = s_var.get();
	a->set(i);
	for (int j=0;j<3;j++)
	{
		printf("%d value: %d.\n", j, a->get());
	}
	printf("%s(%d) exit: 0x%p; %d;\n", __FUNCTION__, i, a, a->get());
	return 0;
}


int main(int argc, char *argv[])
{
	for (int i = 0; i < 3; i++)
	{

		Thread* trd = Thread::Run(ThreadProcTest, i);
		trd->Join();
		delete trd;

		Thread::Sleep(2000);
	}

	getchar();
	return 0;
}